#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> arr(n + 1);
  for (int i = 1; i <= n; i ++) cin >> arr[i];
  arr.insert(arr.end(), arr.begin() + 1, arr.end());
  vector<vector<int>> sum(2 * n + 1, vector<int>(2 * n + 1));
  for (int i = 1; i <= 2 * n; i ++) {
    for (int j = i; j <= 2 * n; j ++) {
      sum[i][j] = ((sum[i][j - 1] + arr[j]) % 10 + 10) % 10;
    }
  }
  auto calc = [&](const auto &cmp) {
    vector<vector<vector<i64>>> dp(2 * n + 1, vector<vector<i64>>(2 * n + 1, vector<i64>(m + 1, -1)));
    for (int l = 2 * n; l >= 1; l --) {
      for (int r = l; r <= 2 * n; r ++) {
        dp[l][r][1] = sum[l][r];
        for (int k = 2; k <= min(r - l + 1, m); k ++) {
          for (int c1 = 1; c1 < k; c1 ++) {
            int c2 = k - c1;
            for (int p = l; p < r; p ++) {
              if (dp[l][p][c1] == -1 || dp[p + 1][r][c2] == -1) continue;
              i64 v = dp[l][p][c1] * dp[p + 1][r][c2];
              if (dp[l][r][k] == -1) dp[l][r][k] = v;
              else dp[l][r][k] = cmp(dp[l][r][k], v);
            }
          }
        }
      }
    }
    i64 ans = dp[1][n][m];
    for (int l = 2, r = l + n - 1; r <= 2 * n; l ++, r ++) {
      ans = cmp(ans, dp[l][r][m]);
    }
    return ans;
  };
  cout << calc([](i64 a, i64 b) { return min(a, b); }) << endl;
  cout << calc([](i64 a, i64 b) { return max(a, b); }) << endl;
}